﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml;

namespace PriceHistoryService
{
    /// <summary>
    /// Summary description for $codebehindclassname$
    /// </summary>
    
    public class GetPriceHistoryWithPOST : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            HelperFunctions hlp = new HelperFunctions();
            string strTicker;
            string strStartDate;
            string strEndDate;
            if (context.Request.HttpMethod == "POST")
            {
                if (context.Request.Form["ticker"] != null)
                    strTicker = context.Request.Form["ticker"].ToString();
                else
                    strTicker = "MSFT";

                if (context.Request.Form["startdate"] != null)
                    strStartDate = context.Request.Form["startdate"].ToString();
                else
                    strStartDate = "1-1-2008";

                if (context.Request.Form["enddate"] != null)
                    strEndDate = context.Request.Form["enddate"].ToString();
                else
                    strEndDate = "1-1-2009";

                XmlDocument xReturn = hlp.getXML(strTicker, strStartDate, strEndDate);

                context.Response.ContentType = "text/xml";
                context.Response.Write(xReturn.OuterXml);

            }
            else
            {
                context.Response.Write("This must be called with an HTTP-POST with params in the header");
            }
            
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
